package me.zhengjie.config.thread

import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
import jakarta.annotation.PostConstruct

@Component
class AsyncTaskProperties {

    companion object {
        var corePoolSize: Int = 0
        var maxPoolSize: Int = 0
        var keepAliveSeconds: Int = 0
        var queueCapacity: Int = 0
    }

    @Value("\${task.pool.core-pool-size}")
    private lateinit var corePoolSizeValue: String

    @Value("\${task.pool.max-pool-size}")
    private lateinit var maxPoolSizeValue: String

    @Value("\${task.pool.keep-alive-seconds}")
    private lateinit var keepAliveSecondsValue: String

    @Value("\${task.pool.queue-capacity}")
    private lateinit var queueCapacityValue: String

    @PostConstruct
    fun init() {
        corePoolSize = corePoolSizeValue.toInt()
        maxPoolSize = maxPoolSizeValue.toInt()
        keepAliveSeconds = keepAliveSecondsValue.toInt()
        queueCapacity = queueCapacityValue.toInt()
    }
}